package main

import (
	"context"
	"fmt"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rpcinterface/client/pay"
	pay2 "git.900sui.cn/kc/rpcinterface/interface/pay"
	"github.com/robfig/cron"
	"time"
)

func filepath() string {
	path := kcgin.AppConfig.String("xindalu.hZ.ftp.path")
	t := time.Now()
	year := t.Format("2006")
	return fmt.Sprintf("%s%s%s", path, year, "/")
}
func Do() {
	nTime := time.Now()
	yesTime := nTime.AddDate(0, 0, -1)
	logDay := yesTime.Format("20060102")
	logs.Info("分账订单下载开始: 日期: %s", logDay)
	path := filepath()
	logs.Info("path %s", path)
	//每天分账订单下载
	file := new(pay.FileDownload).Init()
	ctx := context.Background()
	args := &pay2.ArgsSplitaccount{
		CustId: kcgin.AppConfig.String("xindalu.hZ.AgetId"),
		Cid:    "388",
		Path:   path,
	}
	reply := false
	err := file.SplitaccountDownload(ctx, args, &reply)
	if err != nil {
		logs.Info("err: %s", err.Error())
	}
	logs.Info("分单账单下载完成")
	logs.Info("分账账单下载结果:【%v】", reply)
}

/**
 * 上海银行提现结果业务处理
 * 每天10点钟执行
 */
func main() {
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	c := cron.New()
	//每天十点执行
	// 0 0 10 * * *
	spec := "0 0 10 * * ?" //秒-分-时-日-月-周【忽略】
	_ = c.AddFunc(spec, Do)
	c.Start()
	select {}
}
